/**
 * Project Name:kany-utils
 * File Name:LinkLabel.java
 * Package Name:me.kany.utils.swt.label
 * Date:2016年5月3日上午11:41:46
 * Copyright (c) 2016, Jason.Wang All Rights Reserved.
 *
*/

package me.kany.utils.swt.label;

import java.awt.Color;
import java.awt.Cursor;
import java.awt.Font;
import java.awt.Graphics2D;
import javax.swing.JLabel;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

/**
 * ClassName:LinkLabel <br/>
 * Function: 自定义的链接标签. <br/>
 * Date: 2016年5月3日 上午11:41:46 <br/>
 * 
 * @author Jason.Wang
 * @version
 * @since JDK 1.7
 * @see
 */
@SuppressWarnings("serial")
public class LinkLabel extends JLabel {
	public LinkLabel(String text) {
		/**
		 * 添加监听事件
		 */
		addMouseListener(new MouseAdapter() {
			@Override
			public void mouseEntered(MouseEvent e) {
				LinkLabel linkLabel = (LinkLabel) e.getSource();
				int height = (linkLabel.getHeight() + linkLabel.getFont().getSize()) / 2 + 1;
				int width = linkLabel.getWidth();
				Graphics2D g2d = (Graphics2D) linkLabel.getGraphics();
				g2d.setColor(linkLabel.getParent().getBackground());
				g2d.drawLine(0, height, width, height);
				super.mouseEntered(e);
			}

			@Override
			public void mouseExited(MouseEvent e) {
				LinkLabel linkLabel = (LinkLabel) e.getSource();
				int height = (linkLabel.getHeight() + linkLabel.getFont().getSize()) / 2 + 1;
				int width = linkLabel.getWidth();
				Graphics2D g2d = (Graphics2D) linkLabel.getGraphics();
				g2d.setColor(Color.BLUE);
				g2d.drawLine(0, height, width, height);
				super.mouseExited(e);
			}

		});
		setText(text);
		setFont(new Font("宋体", 0, 12));
		setForeground(Color.BLUE);
		setCursor(new Cursor(12));
		setBorder(null);
		setOpaque(false);
		setRequestFocusEnabled(false);
	}
}
